package site.isscloud.project.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import site.isscloud.framework.config.MqttConfig;
import site.isscloud.project.mqtt.ProjectMqttMessageHandler;

import javax.annotation.PostConstruct;

/**
 * 项目MQTT配置
 */
@Configuration
@ConditionalOnProperty(name = "mqtt.enabled", havingValue = "true")
public class ProjectMqttConfig {

    @Autowired
    private MqttConfig mqttConfig;

    @Autowired
    private ProjectMqttMessageHandler projectMqttMessageHandler;

    /**
     * 应用启动后设置消息处理器
     */
    @PostConstruct
    public void init() {
        // 将业务消息处理器设置到框架MQTT配置中
        mqttConfig.setMessageHandler(projectMqttMessageHandler);
        System.out.println("MQTT消息处理器设置完成");
    }
}